<?php

/** libraries
 * http://docs.joomla.org/JToolBarHelper
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla view library
jimport('joomla.application.component.view');

class bgViewbg extends JView
{
	// Overwriting JView display method
	function display($tpl = null) 
	{
	   
	   $model = $this->getModel();
       $aut = new bgAuthorize();
       
       $task = JRequest::getVar('task');
       switch($task){
        
            case 'error':
                $this->row = (object)JRequest::getVar('jform');
                
                //Get List Leader type
                $this->list_cocm = $model->getAllCocm();
                
                $this->setLayout('a01271');
                JToolBarHelper::save('save','登録');
               	JToolBarHelper::cancel('cancel', 'キャンセル');
                JToolBarHelper::title( '指導員資格作成','certification.png' );
                
                break;
            case 'edit':
                $cid = JRequest::getVar('cid');
                $cid = is_array($cid) ? $cid[0] : $cid;
                if($cid){
                    $this->row = $model->load($cid);
                }else{
                    //die('Not found');
                    die("データは見つかりませんでした");
                }
                //Get List Leader type
                $this->list_cocm = $model->getAllCocm();
                
                $this->setLayout('a01272');
                
                JToolBarHelper::title( '指導員資格編集','certification.png' );
                JToolBarHelper::save('save','登録');
               	JToolBarHelper::cancel('cancel', 'キャンセル'); 
                
                break;
            case 'add':
                
                //Get List Leader type
                $this->list_cocm = $model->getAllCocm();
                
                $this->setLayout('a01271');
                
                JToolBarHelper::title( '指導員資格作成','certification.png' );
                JToolBarHelper::save('save','登録');
               	JToolBarHelper::cancel('cancel', 'キャンセル');              
                
            break;
            
            case 'popup_coch':
                
                //$this->list_coch =& $model->getAllCoch();
                               
                $this->setLayout('popup_coch');
            break;
            case 'popup_ocba':
                
                $this->list_ocba =& $model->getAllOcba();
                               
                $this->setLayout('popup_ocba');
            break;
                         
            default:
                             
                //search
                $this->list['filter_search'] = &JRequest::getVar('filter_search');
                
                //Kiem tra co quyen Edit
                //if($aut->checkEditOwn()){
//                    $this->list['user_id'] =  $aut->getUserID();
//                    $this->rows =& $model->getAllCertification($this->list);
//                }else{
//                    
//                }
                
                $this->rows =& $model->getAllCertification($this->list);
                
                // Get data from the model
                //$this->rows =& $model->getAllCertification($this->list);  
                $this->pagination =& $this->get('Pagination');
                                                
                
                JToolBarHelper::title( '指導員資格管理','certification.png' );
                
                if($aut->checkAdd()){
                    JToolBarHelper::addNew('add','作成');
                }
                
                if($aut->checkEdit() || $aut->checkEditOwn()){
            	   JToolBarHelper::editList('edit', '編集');
                }
                
                if($aut->checkDelete()){
            	   JToolBarHelper::deleteList('', 'remove','削除');
                }
                
                $this->setLayout('a01270');
       }
        
		parent::display($tpl);
       
	}
}




